{include file="common/head"/}
<div class="layui-fluid"><div class="layui-card"><div class="layui-card-body">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{:lang('user')}{:lang('list')}</legend>
    </fieldset>
    <div class="demoTable">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}关键字">
        </div>
        <button class="layui-btn" id="search" data-type="reload">搜索</button>
        <a href="{:url('index')}" class="layui-btn">显示全部</a>
        <a href="{:url('mtree')}" class="layui-btn layui-btn-danger"><i class="layui-icon layui-icon-group"></i>会员结构图</a>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
</div>
</div>
<script type="text/html" id="is_lock">
    {{# if(d.is_lock==1){ }}
    <a class="layui-btn layui-btn-mini layui-btn-danger" style='line-height:28px;' lay-event="is_lock">禁用</a>
    {{# }else{  }}
    <a class="layui-btn layui-btn-mini layui-btn-warm" style='line-height:28px;' lay-event="is_lock">正常</a>
    {{# } }}
</script>
<script type="text/html" id="action">
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-mini" style='line-height:28px;'>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del" style='line-height:28px;'>删除</a>
</script>
<script type="text/html" id="fmt_level">
    F{{d.level}}   
</script>


{include file="common/foot"/}
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            id: 'user',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page: true,
            cols: [[
                {checkbox:true,fixed: true},
                {field: 'id', title: '{:lang("id")}', width: 60, fixed: true},
                {field: 'username', title: '用户名', width: 120},
                {field: 'nickname', title: '呢称', width: 120},
                {field: 'level', title: '会员等级', width: 100, templet:'#fmt_level'},
                {field: 'parent', title: '上级会员', width:120},
                {field: 'invint_id', title: '推广码', width:90},
                {field: 'money', title: '零钱包', width:90},
                {field: 'coin', title: 'F币', width:90},
                {field: 'is_lock', align: 'center',title: '状态', width: 100,toolbar: '#is_lock'},
                {field: 'reg_time', title: '注册时间', width: 180},
                {field: 'last_login', title: '最后登录时间', width: 180},
                {field: 'last_ip', title: '最后登录IP', width: 150},
                {width: 160, align: 'center', toolbar: '#action'}
            ]],
            limit: 10 //每页默认显示的数量
        });
        //搜索
        $('#search').on('click', function() {
            var key = $('#key').val();
            if($.trim(key)==='') {
                layer.msg('{:lang("pleaseEnter")}关键字！',{icon:0});
                return;
            }
            tableIn.reload({
                where: {key: key}
            });
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'is_lock') {
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post('{:url("usersState")}', {'id': data.id}, function (res) {
                    layer.close(loading);
                    if (res.status ===1) {
                        if (res.is_lock === 1) {
                            obj.update({
                                is_lock: '<a class="layui-btn layui-btn-mini layui-btn-danger" lay-event="is_lock">禁用</a>'
                            });
                        } else {
                            obj.update({
                                is_lock: '<a class="layui-btn layui-btn-mini layui-btn-warm" lay-event="is_lock">正常</a>'
                            });
                        }
                    } else {
                        layer.msg('操作失败！', {time: 1000, icon: 2});
                        return false;
                    }
                })
            }else if (obj.event === 'del') {
                layer.confirm('您确定要删除该会员吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('usersDel')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

		
        $('#delAll').click(function(){
            layer.confirm('确认要删除选中信息吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('user'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('delall')}", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
    });
</script>
</body>
</html>